<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Poll/classes/PhpFox_ComponentRandomPoll.class.php, $Author:  $ */



/** Component for showing random poll
 *   
 * @version $Id: PhpFox_ComponentRandomPoll.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.poll
 */
class PhpFox_Mod_Poll_ComponentRandomPoll extends BaseComponent
{
    function process()
    {
       	$oPollService = &$this->_oModule->getService('Poll');
       	/* @var $oPollService PhpFox_Mod_Poll_ServicePoll */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oTpl = &$this->_oModule->getTemplate();

        if (!$oSecurityService->checkAccess('poll', '', false))
        {
            return '';
        }

        $aItem = $this->oDatabase->getRow("SELECT id, user, o1, o2, o3, o4, poll FROM ". App::getT('polls') ." 
        	USE INDEX (type)
			WHERE type = '0' ORDER BY RAND() LIMIT 1");

        $oTpl->assign(array(
            'aItem'      => $aItem,
            'bVoted'     => isset($aItem['id']) ? $oPollService->isUserCanVote($aItem['id']) : '',
            'sUImageUrl' => App::getParam('user.pic.url'),
        ));
        return $oTpl->fetch('RandomPoll.html');
    }
}
?>